// Ajax form upload
function uploadImage() {
	// Open
	$('#openDialog').click();
}

var optionsUpload = {
		complete : function(response) {
			response.responseText = response.responseText.replace("<PRE>", "");
			response.responseText = response.responseText.replace("</PRE>", "");
			response.responseText = response.responseText.replace("<pre>", "");
			response.responseText = response.responseText.replace("</pre>", "");
			var json = eval('(' + response.responseText + ')');
			console.log(json);
				$("#image").empty();
				$("#image")
						.append(
								'<img src="imagesUserUploaded_tmp/'
										+ json.fileName
										+ '" width="280px" />'
										+ '<input type="hidden" name="memberAvt" id="memberAvt" value="'
										+ json.fileName + '" />');
			
		},
		error : function() {

		}

	};
	$('#openDialog').live('change', function() {
		$("#formUpload").ajaxForm(optionsUpload).submit();
	});
	
	function updateInfo() {
		var email = $('#email').val();
		var memberNm = $('#memberNm').val();
		var birthDay = $('#birthDay').val();
		var gender = $('#gender').val();
		var memberAvt = $('#memberAvt').val();
		var receiveEmail = $('#receiveEmail').val()=='true'?1:2;
		
		var dataString = {
				'email' : email,
				'memberNm' : memberNm,
				'birthDay' : birthDay,
				'gender' : gender,
				'memberAvt' : memberAvt,
				'receiveEmail' : receiveEmail,
			};
			$.ajax({
				dataType : 'json',
				type : 'POST',
				url : 'updateInfo',
				data : dataString,
				complete : function(data) {
					
					if(data.status == 200){
						var json = JSON.parse(data.responseText);
						 BootstrapDialog.alert('Thông tin cá nhân của bạn đã được lưu lại thành công.', function(){
//							 parent.$.fancybox.close();
							 //window.top.location.href =  'member?memberId=' + json.model.memberId; 
							 // window.top.location.href = 'member?memberId=' + json.model.memberId; 
					        });
						 
					}else{
						alert('dang ky that bai');
					}
					
					
				}

			});
	}